/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Localizacao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author fellipe
 */
public class EnderecoHelper {
    
    Session session = null;

    public EnderecoHelper() {
            this.session = HibernateUtil.getSessionFactory().getCurrentSession();
            //this.session = HibernateUtil.getSessionFactory().openSession();
        
    }
    
    public List consultar()
    {
        List<Endereco> endList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery ("from Endereco");
            endList = (List<Endereco>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return endList;
    }
    
    public Endereco getEnderecoById(int id)
    {
        Endereco endereco = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery ("from Endereco where = " + id);
            endereco = (Endereco) q.uniqueResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return endereco;
    }
}
